﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace Common
{
    /// <summary>
    /// 使用MD5加密的帮助类
    /// </summary>
    public class MD5Helper
    {
        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static string MD5Encrypt64(string password)
        {
            //string pwd = "";
            MD5 md5 = MD5.Create(); //实例化一个md5对像
                                    // 加密后是一个字节类型的数组，这里要注意编码UTF8/Unicode等的选择　
            byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(MD5Coding(password)));
            return Convert.ToBase64String(s);
        }
        /// <summary>
        /// 加盐MD5
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        private static string MD5Coding(string password)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("014");
            sb.Append(password);
            sb.Append(';');
            return sb.ToString();
        }
    }
}
